package com.web.note;

import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.util.EntityUtils;

public class Post_jsp {

	public boolean onLine(){
		return false;
	}
	
	
	public String connServerForResult(String strUrl) { 
		
        // HttpGet对象 

		
		

        HttpGet httpRequest = new HttpGet(strUrl); 
        String strResult = ""; 


        try { 

            // HttpClient对象 
        	
            HttpClient httpClient = new DefaultHttpClient(); 
            httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
//            httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 40000);
            // 获得HttpResponse对象 

            HttpResponse httpResponse = httpClient.execute(httpRequest); 

            if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { 

                // 取得返回的数据 

                strResult = EntityUtils.toString(httpResponse.getEntity(),"UTF-8"); 

            } 

        } catch (ClientProtocolException e) { 

        	
            e.printStackTrace(); 
            return "0";
        } catch (IOException e) { 
        	
            e.printStackTrace(); 
            return "0";
        } 

        return strResult; 

    } 
}
